package com.itheima.studenthomework.dao;

import com.itheima.studenthomework.domain.Student;

import java.util.ArrayList;

public class StudentDao {
    private static ArrayList<Student> list = new ArrayList<>();
    public boolean addStudent(Student student) {
        list.add(student);
        return true;
    }

    public ArrayList<Student> giveList(){
        return list;
    }


    public boolean updateStudent(Student stu) {
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if(stu.getId().equals(student.getId())){
                list.set(i,stu);
                return true;
            }
        }
        return false;
    }

    public boolean deleteStudent(int index) {
        list.remove(index);
        return true;
    }

    public Student findOneStudent(int index) {
        Student student = list.get(index);
        return student;
    }
}
